<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>应用服务管理</title>
    <link href="../../../../../lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../../../../lib/ui/js/plugins/datepicker/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="../../../../../content/pc/sysmgt/unitmanage/layui/css/layui.css">
    <link rel="stylesheet" href="../../../../../content/pc/sysmgt/unitmanage/css/changan.css">
    <!-- <link href="../../../../../lib/bootstrap/css/bootstrap-switch.min.css" rel="stylesheet"> -->
    <style>
        .layui-form-item{
            position: relative;
        }
        .mask-container{
            width: 50px;
            height: 20px;
            position: absolute;
            bottom: 4px;
        }
    </style>
</head>
<body>
<div class="body">
    <section class="table-box">
        <section class="table-box-body">
            <main class="table_cont">
                <div class="table_cont_inner">
                    <div class="table-header">
                        <h2 class="table-h2">应用服务管理</h2>
                    </div>
                    <div class="table-body">
                        <div class="table-tapple">
                            <div class="table-top">
                                <div class="table-top-tit">
                                    <button class="top-tit-btn dialog1btn">部署应用</button>
                                </div>
                            </div>
                        </div>
                        <div class="table-list-box">
                            <!-- 下面是列表div内容 -->
                            #if(recordList!=null)
                            #for(x:recordList)
                                #if(recordList!=null)
                                    <div class="table-grid table-grid-switchNetContainer"  data-value="#(x.get('conflict_id'))">
                                        <div class="table-grid-box">
                                            <div class="table-grid-top">
                                                <div class="table-grid-txt">
                                                    <a href="yingyong1.html">
                                                    <div class="table-grid-txt-title">指令数据</div>
                                                    #if(x.get("orderSize")!=null)
                                                        <div class="table-grid-txt-value">#(x.get("orderSize"))</div>
                                                    #else
                                                        <div class="table-grid-txt-value">0</div>
                                                    #end
                                                    </a>
                                                </div>
                                                <div class="table-grid-txt">
                                                    <a href="yingyong2.html">
                                                    <div class="table-grid-txt-title">状态数据</div>
                                                    #if(x.get("stateSize")!=null)
                                                        <div class="table-grid-txt-value">#(x.get("stateSize"))</div>
                                                    #else
                                                        <div class="table-grid-txt-value">0</div>
                                                    #end
                                                    </a>
                                                </div>
                                                <div class="table-grid-txt">
                                                    <a href="yingyong3.html">
                                                    <div class="table-grid-txt-title">存证数据</div>
                                                    #if(x.get("evidenceSize")!=null)
                                                        <div class="table-grid-txt-value">#(x.get("evidenceSize"))</div>
                                                    #else
                                                        <div class="table-grid-txt-value">0</div>
                                                    #end
                                                    </a>
                                                </div>
                                            </div>
                                            <div class="table-grid-bd">
                                                <h3 class="table-grid-h3">
                                                    运行状态
                                                    <span class="table-grid-bd-subtitle"></span>
                                                    #if(x.get("attrib_10")=="" || x.get("attrib_10")==null)
                                                        <span class="table-grid-button"></span>
                                                    #end
                                                    #if(x.get("attrib_10")=="异常")
                                                        <span class="table-grid-button  is-error">#(x.get("attrib_10"))</span>
                                                    #end
                                                    #if(x.get("attrib_10")=="正常")
                                                        <span class="table-grid-button  is-pass">#(x.get("attrib_10"))</span>
                                                    #end
                                                    #if(x.get("attrib_10")=="停止")
                                                        <span class="table-grid-button  is-off">#(x.get("attrib_10"))</span>
                                                    #end
                                                    #if( roles.toString().contains("站点管理员"))
                                                        <div class="layui-form">
                                                            <div class="layui-form-item layui-form-item-run">
                                                                <div class="layui-input-block">
                                                                    <input type="checkbox" checked="true" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="开|关" data-text="运行状态"  class="switchInput switchNetInputRun" data-value="#(x.get('conflict_id'))">
                                                                    <!-- <input type="checkbox" class="switchInput"    checked="" > -->
                                                                    <div class="mask-container" data-text="运行状态"  class="switchInput" data-value="#(x.get('conflict_id'))" onclick="changeSwitchFun(this)"></div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    #end
                                                </h3>
                                                <div class="table-grid-item">
                                                        <div class="table-grid-label"><label>站点名称</label></div>
                                                        <div class="table-grid-controls">
                                                            <div class="table-grid-text">#(x.get("attrib_37"))</div>
                                                        </div>
                                                </div>
                                                <div class="table-grid-item">
                                                    <div class="table-grid-label"><label>联系电话</label></div>
                                                    <div class="table-grid-controls">
                                                        <div class="table-grid-text">#(x.get("attrib_06"))</div>
                                                    </div>
                                                </div>
                                                <div class="table-grid-item">
                                                    <div class="table-grid-label"><label>存证任务状态</label></div>
                                                    <div class="table-grid-controls">
                                                        <div class="table-grid-text">
                                                            <div class="layui-form">
                                                                <div class="layui-form-item layui-form-item-evidence">
                                                                    <div class="layui-input-block">
                                                                        <input type="checkbox" checked="true" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="开|关" data-text="存证任务状态"  class="switchInput switchNetInputEvidence" data-value="#(x.get('conflict_id'))">
                                                                        <div class="mask-container" data-text="存证任务状态"  class="switchInput" data-value="#(x.get('conflict_id'))" onclick="changeSwitchFun(this)"></div>
                                                                        <!-- <input type="checkbox" checked=""  data-value="#(x.get('conflict_id'))" class="switchInput" data-text=""> -->
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="table-grid-item">
                                                    <div class="table-grid-label"><label>共享任务状态</label></div>
                                                    <div class="table-grid-controls">
                                                        <div class="table-grid-text">
                                                            <div class="layui-form">
                                                                <div class="layui-form-item layui-form-item-share">
                                                                    <div class="layui-input-block">
                                                                        <!-- <input type="checkbox"  name="close"  data-value="#(x.get('conflict_id'))" class="switchInput"  data-text="共享任务状态"> -->
                                                                        <input type="checkbox" checked="true" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="开|关" data-text="共享任务状态" class="switchInput switchNetInputShare" data-value="#(x.get('conflict_id'))">
                                                                        <div class="mask-container" data-text="共享任务状态" class="switchInput" data-value="#(x.get('conflict_id'))" onclick="changeSwitchFun(this)"></div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="table-grid-botbtn">
                                                    #if(roles==null)
                                                        <button class="top-tit-btn" onclick="unitManagementOnclick(this)" value="#(x.get('conflict_id'))">运行管理</button>
                                                    #else
                                                        #if( roles.toString().contains("管理"))
                                                            <button class="top-tit-btn" onclick="unitManagementOnclick(this)" value="#(x.get('conflict_id'))">运行管理</button>
                                                        #end
                                                    #end
                                                    <button class="top-tit-btn"  onclick="businessOnclick(this)"  value="#(x.get('conflict_id'))">业务展示</button>
                                                </div>
                                            </div>
                                            <div class="table-grid-btn table-grid-down">
                                                <button class="table-btn table-btn-icon dropDownMenu" data-value="#(x.get('conflict_id'))"> <i class="teble-icon table-icon-more" role="img" aria-label="more"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                #end
                            #end
                        #end
                </div>

                </div>

                </div>

            </main>

        </section>
    </section>
</div>
<script src="../../../../../content/pc/sysmgt/unitmanage/layui/layui.js"></script>
<script src="../../../../../lib/jquery/jquery.min.js"></script>
<script src="../../../../../lib/bootstrap/js/bootstrap.min.js"></script>
<script src="../../../../../lib/ui/js/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="../../../../../content/pc/sysmgt/unitmanage/js/jquery.min.js"></script>
<!-- <script src="../../../../../lib/bootstrap/js/bootstrap-switch.min.js"></script> -->
<script>
    // 应用服务单元管理--运行管理页面
    function unitManagementOnclick(e) {
        //应用服务单元管理--运行管理页面
        window.open('/sysadmin/remoteApp/unitManagement?cid='+$(e).attr('value'), "_self");
    }
    //应用服务单元管理-应用管理
    function businessOnclick(e) {
        //应用服务单元管理--运行管理页面
        window.open('/sysadmin/remoteApp/smartContracts?cid='+$(e).attr('value'), "_self");
    }
    layui.use(['dropdown', 'util', 'layer', 'table'], function () {
        var dropdown = layui.dropdown
            , util = layui.util
            , layer = layui.layer
            , table = layui.table
            , $ = layui.jquery;
        dropdown.render({
            elem: '.dropDownMenu'
            , align: 'right',
            content: ['<div class="table-dropdown-box">'
                , '<ul class="table-list-option">'
                , '<li class="delect" onclick="deletFun(this)">删除</li>'
                // , '<li class="delect" onclick="subscribeToFun()">订阅</li>'
                , '</ul>'
                , '</div>'].join('')
            , style: 'width: 100px;  '
            , ready: function (elemPanel,elem) {
                //当前点击的元素的--data-value
                let dataValue=$(elem).attr('data-value');
                $('.table-dropdown-box .delect').attr('data-value',dataValue);
            }
        });
    });
    function changeSwitchFun(elem){
        let dataText=$(elem).attr('data-text');
        let dataValue=$(elem).attr('data-value');
        let bortherDom=$(elem).siblings();
        let thisDomValue=$($(bortherDom)[1]).hasClass('layui-form-onswitch')?true:false;//$(bortherDom).prop('checked');//layui-form-onswitch  有的话是开，没得话是关
        layer.open({
            type: 1, //可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。 若你采用layer.open({type: 1})方式调用，则type为必填项（信息框除外）
            title :'请问是否要继续切换'+dataText,
            area: ['300px', '200px'],
            closeBtn: 0,
            content:$('#detail-template').html(), //这里content是一个普通的String
            btn: ['继续','取消'],
            yes: function(index, layero){
                if(dataText=='运行状态'){
                    $.post("/sysadmin/remoteApp/switchAppStatusByCid",{"cid":dataValue,"status":!thisDomValue},function(result){
                        if(result.msg=='操作成功'){
                            if($($(bortherDom)[1]).hasClass('layui-form-onswitch')){//开
                                $($(bortherDom)[1]).removeClass('layui-form-onswitch');
                            }else{//关
                                $($(bortherDom)[1]).addClass('layui-form-onswitch');
                            }
                            layer.close(index);
                        }else{
                            layer.msg(result.error);
                            layer.close(index);
                        }
                    },"json");
                }else if(dataText=='存证任务状态'){
                    $.post("/sysadmin/remoteApp/switchFileStatusByCid",{"cid":dataValue,"status":!thisDomValue},function(result){
                        if(result.msg=='操作成功'){
                            if($($(bortherDom)[1]).hasClass('layui-form-onswitch')){//开
                                $($(bortherDom)[1]).removeClass('layui-form-onswitch');
                            }else{//关
                                $($(bortherDom)[1]).addClass('layui-form-onswitch');
                            }
                            layer.close(index);
                        }else{
                            layer.msg(result.error);
                            layer.close(index);
                        }
                    },"json");
                }else if(dataText=='共享任务状态'){
                    $.post("/sysadmin/remoteApp/switchDataStatusByCid",{"cid":dataValue,"status":!thisDomValue},function(result){
                        if(result.msg=='操作成功'){
                            if($($(bortherDom)[1]).hasClass('layui-form-onswitch')){//开
                                $($(bortherDom)[1]).removeClass('layui-form-onswitch');
                            }else{//关
                                $($(bortherDom)[1]).addClass('layui-form-onswitch');
                            }
                            layer.close(index);
                        }else{
                            layer.msg(result.error);
                            layer.close(index);
                        }
                    },"json");
                }
            },
            cancel:function(index, layero){
                if($($(bortherDom)[1]).hasClass('layui-form-onswitch')){//开
                    $($(bortherDom)[1]).removeClass('layui-form-onswitch');
                }else{//关
                    $($(bortherDom)[1]).addClass('layui-form-onswitch');
                }
                layer.close(index);
            },
        });
    }
    //删除事件
    function deletFun(elem){
        let dataValue=$(elem).attr('data-value');
        $.post("/sysadmin/remoteApp/deletePublicMethods",{"cid": dataValue},function(result){
            layer.msg(result.data.msg);
            location.reload(true);
        },"json");
    }
    //开关的事件  switchInput
    $('.dialog1btn').click(function () {
        $('.dialog').show();
    });
    $('.close1').click(function () {
        $('.dialog').hide();
    });
    //调用开关状态的接口
    function switchNetFun(){
        $('.table-grid-switchNetContainer').each((index, element)=>{//index是下标 element 是元素
            let dataValue=$(element).attr('data-value');//cid
            $.post("/sysadmin/remoteApp/selectUnitStatusByCid",{"cid":dataValue},function(result){
                let evidenceSwitch=result.fileStatus==null?false:result.fileStatus;//存证
                let shareSwitch=result.dataStatus==null?false:result.dataStatus;//共享
                let runSwitch=result.appStatus==null?false:result.appStatus;//运行
                // 运行状态开关
                if(runSwitch){//开
                    $(element).find('.layui-form-item-run .layui-unselect').addClass('layui-form-onswitch');
                }else{//关
                    $(element).find('.layui-form-item-run .layui-unselect').removeClass('layui-form-onswitch');
                }
                //存证
                if(evidenceSwitch){//开
                    $(element).find('.layui-form-item-evidence .layui-unselect').addClass('layui-form-onswitch');
                }else{//关
                    $(element).find('.layui-form-item-evidence .layui-unselect').removeClass('layui-form-onswitch');
                }
                //共享
                if(shareSwitch){//开
                    $(element).find('.layui-form-item-share .layui-unselect').addClass('layui-form-onswitch');
                }else{//关
                    $(element).find('.layui-form-item-share .layui-unselect').removeClass('layui-form-onswitch');
                }
            },"json");
        });
    }
    $(function(){
        //调用开关状态的接口
        switchNetFun();
    });
</script>
</body>
</html>
